/*
 *  $Id: CrucifixBanishing.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *  This file is a part of Ragima CCG.
 *  (C) 2008 Ragima development group.
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;

namespace Ragima.Cards001.Light.Abilities {
    public class CrucifixBanishing: AbilityCard<Creature> {
        public CrucifixBanishing(): base("001_l_a_crucifix_banishing") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Light;
            Target = new CreatureTarget(GetTargetPhrase(), true, true, IsNeighbourDemon);
            AddManaCost(ElementType.Light, 4);
        }

        private static bool IsNeighbourDemon(TargetRequest request, Creature cr) {
            Creature caster = request.Caster as Creature;
            return caster != null && cr.Race.IsRace<Races.Demon>() && cr.DistanceTo(caster) <= 1;
        }

        protected override void DoAction(TargetArgs<Creature> args) {
            int mana = Math.Min(args.Target.Owner.GetMana(ElementType.Darkness), 4);
            if (mana > 0) args.Target.Owner.DecrementMana(ElementType.Darkness, mana);
            DemonCreatureCard card = args.Target.Card as DemonCreatureCard;
            if (card != null && card.PactValue > 1) args.Caster.DamageBy(NewDamage(args, DamageType.Darkness, card.PactValue-1));
            int dice = args.Player.Game.GetDiceNextValue();
            if (dice >= 4)
                args.Target.Death();
            else
                args.Target.Summary.ChangeMaxHealth(-(args.Target.Health-1));
        }
    }
}
